package com.fc.mall.controller;

import com.fc.mall.base.object.Result;
import com.fc.mall.dto.CommonResult;
import com.fc.mall.dto.SmsBargainParam;
import com.fc.mall.dto.SmsBargainProdRequest;
import com.fc.mall.service.SmsBargainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by sunny on 2019/9/24.
 */
@Api("砍价商品管理API")
@RestController
@RequestMapping("/sms/bargain")
public class SmsBargainController {

    @Autowired
    private SmsBargainService smsBargainService;

    @ApiOperation("获取砍价商品列表")
    @GetMapping("list")
    public CommonResult list(SmsBargainParam smsBargainParam,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
    {

        return  new CommonResult().pageSuccess(smsBargainService.queryProductBargainList(smsBargainParam, pageNum, pageSize));
    }


    @ApiOperation("添加或更新砍价商品信息")
    @PostMapping
    public Result createOrUpdateBargainProduct(@RequestBody SmsBargainProdRequest bargainProdRequest)
    {
        smsBargainService.createOrUpdateBargainProduct(bargainProdRequest);
        return Result.success();
    }

    @ApiOperation("获取砍价产品信息")
    @GetMapping("{bargainId}")
    public Result getBargainProduct(@PathVariable("bargainId") Long bargainId)
    {
        return Result.success(smsBargainService.getBargainProductById(bargainId));
    }

    @ApiOperation("删除砍价商品")
    @DeleteMapping("{bargainId}")
    public Result delBargainProduct(@PathVariable("bargainId") Long bargainId)
    {
        return Result.success(smsBargainService.delBargainProductId(bargainId));
    }
}
